<%--
  Created by IntelliJ IDEA.
  User: 王韫琛
  Date: 2021/1/29
  Time: 2:12
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>修改密码</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/webjars/layui/2.5.6/css/layui.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/webjars/layui/2.5.6/layui.all.js">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/webjars/layui/2.5.6/layui.js">
</head>
<body>
<div style="text-align: center;">
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <div class="layui-inline">
        <form action="${pageContext.request.contextPath}/addUser" class="layui-form layui-form-pane" method="post">
            <div class="layui-form-item">
                <label class="layui-form-label" for="pwd">旧密码:</label>
                <div class="layui-input-inline">
                    <input type="password" name="pwd" id="pwd" required lay-verify="required" lay-reqText="请输入密码"
                           placeholder="请输入密码" class="layui-input">
                </div>
            </div>
            <br>
            <div class="layui-form-item">
                <label class="layui-form-label" for="newpwd">新密码:</label>
                <div class="layui-input-inline">
                    <input type="password" name="newpwd" id="newpwd" required lay-verify="required" lay-reqText="请输入密码"
                           placeholder="请输入密码" class="layui-input">
                </div>
            </div>
            <br>
            <div class="layui-form-item">
                <label class="layui-form-label" for="yesPwd">确认密码:</label>
                <div class="layui-input-inline">
                    <input type="password" name="newpwd" id="yesPwd" required lay-verify="required|confirmPass" lay-reqText="请输入密码"
                           placeholder="请输入密码" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-inline" style="padding-left: 45px">
                    <button class="layui-btn" lay-submit lay-filter="doSubmit" lay-event="add">修改</button>
                    <button type="reset" class="layui-btn layui-btn-warm">重置</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script src="${pageContext.request.contextPath}/webjars/layui/2.5.6/layui.js"></script>
<script>
    layui.use(['laydate', 'layer', 'form', 'jquery'], function () {
        var laydate = layui.laydate;
        var form = layui.form;
        var $ = layui.jquery;
        var url = "/userUpdatePwd";
        //标识是否存在
        var flag = false;
        // 校验两次密码是否一致
        form.verify({
            confirmPass:function(value){
                if($('input[name=newpwd]').val() !== value)
                    return '两次密码输入不一致！';
            }
        });

        //表单监听事件
        form.on("submit(doSubmit)", function (data) {
            console.log(data)
            if (flag) {
                layer.msg("信息有误");
            } else {
                $.post(url, data.field, function (result) {
                    if (result.success) {
                        layer.alert(result.message, {icon: 1}, function (index) {
                            layer.close(index);
                        });
                    } else {
                        layer.alert(result.message, {icon: 2});
                    }
                }, "json");
            }
            //禁止页面跳转
            return false;
        });
    });
</script>
</body>
</html>
